<template>
	<view>
		<!-- <view class="inp" @tap="xzBtn">
			<input type="text" :value="stateTxt" />
			<view>选择银行</view>
		</view>
		<view class="inp" @tap="xzBtn1">
			<input type="text" :value="stateTxt1" />
			<view>选择类型</view>
		</view> -->
		<myhead left="1" txt="功能测试"></myhead>
		<view class="inputList" style="margin-top: 3vw;">
		    <view class="title">选择类型</view>
		    <input placeholder="选择类型" v-model="stateTxt1" @tap="xzBtn1" disabled="disabled"></input>
		</view>
		<view class="inputList">
		    <view class="title">转入转出显示名称</view>
		    <input placeholder="请输入转入转出显示名称" v-model="payTypeStr"></input>
		</view>
		<view class="inputList">
		    <view class="title">收付款姓名</view>
		    <input placeholder="请输入收付款姓名" v-model="name"></input>
		</view>
		<view class="inputList">
		    <view class="title">日期</view>
			<picker mode="date" :value="myDate" v-model="myDate" @change="bindDateChange">
				<view class="uni-input">{{myDate}}</view>
			</picker>
		</view>
		<view class="inputList">
		    <view class="title">时间</view>
		    <input placeholder="请输入时间,例12:12 或 12:12:12" v-model="myTime"></input>
		</view>
		<view class="inputList">
		    <view class="title">金额</view>
		    <input placeholder="请输入金额" v-model="num"></input>
		</view>
		<view class="btn" @tap="btn">保存</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				state:null,
				stateTxt1:'',
				payTypeStr:'',
				name:'',
				myDate:'选择日期',
				myTime:'',
				num:null,
				id:null
			}
		},
		onLoad(options) {
			this.id=options.id
		},
		onShow() {
			
		},
		methods: {
			bindDateChange: function(e) {
				this.myDate = e.target.value
			},
			xzBtn:function(){
				let that=this
				uni.showActionSheet({
				    itemList: ['农业银行', '建设银行', '中国银行'],
				    success: function (res) {
				        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						that.state=res.tapIndex
						if(res.tapIndex==0){
							that.stateTxt='农业银行'
						}
						if(res.tapIndex==1){
							that.stateTxt='建设银行'
						}
						if(res.tapIndex==2){
							that.stateTxt='中国银行'
						}
				    },
				    fail: function (res) {
				        console.log(res.errMsg);
				    }
				});
			},
			xzBtn1:function(){
				let that=this
				uni.showActionSheet({
				    itemList: ['转出', '转入'],
				    success: function (res) {
				        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						that.state=res.tapIndex
						if(res.tapIndex==0){
							that.stateTxt1='转出'
						}
						if(res.tapIndex==1){
							that.stateTxt1='转入'
						}
				    },
				    fail: function (res) {
				        console.log(res.errMsg);
				    }
				});
			},
			btn:function(){
				if(!this.stateTxt1){
					uni.showToast({
					  title: '请选择类型',
					  icon: 'none'
					});
					return false
				}
				if(!this.payTypeStr){
					uni.showToast({
					  title: '请输入转入转出显示名称',
					  icon: 'none'
					});
					return false
				}
				if(!this.myDate || this.myDate == '选择日期'){
					uni.showToast({
					  title: '请选择日期',
					  icon: 'none'
					});
					return false
				}
				var reg = RegExp(/：/);
				//console.log(reg.test(this.myTime));
				if(reg.test(this.myTime)){
					uni.showToast({
					  title: '请改为英文冒号',
					  icon: 'none'
					});
					return false
				}
				if(!this.num){
					uni.showToast({
					  title: '请输入金额',
					  icon: 'none'
					});
					return false
				}
				uni.showLoading({
				    title: '加载中'
				});
				var myDateTime=null
				if(this.myTime){
					myDateTime=this.myDate+' '+this.myTime
				}else{
					myDateTime=this.myDate
				}
				http.post('/api/balance/addBalanceDetail',{balanceId:this.id,payType:this.state,amount:this.num,createTime:myDateTime,payTypeStr:this.payTypeStr,name:this.name}).then(res => {
					//console.log(res)
					if (res.code == 200) {
						uni.navigateBack({
						    url:'/pages/bank/bankList'
						})
					}
					uni.hideLoading();
				})
				
			}
		}
	}
</script>

<style>
	page{
		
	}
	.inp{
		width: 84%;
		padding: 2vw 4vw;
		border-radius: 1vw;
		background: #f9f9f9;
		font-size: 3.8vw;
		color: #333333;
		margin: 0 auto;
		border: 1px solid #f2f2f2;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		margin-top: 4vw;
	}
	.inputList{
		padding: 0 4vw;
		margin-bottom: 6vw;
	}
	.inputList .title{
		margin-bottom: 2vw;
		font-size: 3.6vw;
		color: #999999;
	}
	.inputList input,.inputList .uni-input{
		border-radius: 1vw;
		background: #f9f9f9;
		font-size: 3.8vw;
		height: 10vw;
		line-height: 10vw;
		text-indent: 2vw;
	}
	.title span{
		color: #007AFF;
		margin-left: 4vw;
	}
	.btn{
		width: 84%;
		padding: 4vw 0;
		font-size: 3.5vw;
		border-radius: 1.8vw;
		background-image: linear-gradient(45deg, #24EBA9, #10C7B2);
		color: #FFFFFF;
		text-align: center;
		margin: 0 auto;
		margin-top: 10vw;
	}
</style>
